//
//  CSReportController.m
//  CreateWithSuper
//
//  Created by chenjunbo on 2024/7/2.
//  Copyright © 2024 CS. All rights reserved.
//

#import "CSReportController.h"
#import "CSLimitedPopView.h"
#import "CSLimitedController.h"
#import <Photos/Photos.h>
#import "ADModule.h"

@interface CSReportController ()

@property (weak, nonatomic) IBOutlet UIView *navView;

@end

@implementation CSReportController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    if ([[ADModule standardInstance]haveNavAd]){
        self.navView.hidden = false;
        [[ADModule standardInstance]showNavAd:self.navView];
    }else{
        
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    bool showIntOrNav = [ADModule standardInstance].showIntOrNav;

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Create" bundle:nil];
        CSLimitedPopView *popView = [storyboard instantiateViewControllerWithIdentifier:@"CSLimitedPopView"];
        
        popView.modalPresentationStyle = UIModalPresentationOverFullScreen;
        [self presentViewController:popView animated:YES completion:nil];

        UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
        view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
        [[UIApplication sharedApplication].keyWindow addSubview:view];

        popView.okBlock = ^{
            [view removeFromSuperview];
            if (showIntOrNav){
                [popView dismissViewControllerAnimated:NO completion:nil];
            }
            [[ADModule standardInstance]showInterAdWithVC:self dismiss:^{
                if (!showIntOrNav){
                    [popView dismissViewControllerAnimated:NO completion:nil];
                }
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Create" bundle:nil];
                CSLimitedController *vc = [storyboard instantiateViewControllerWithIdentifier:@"CSLimitedController"];
                [self.navigationController pushViewController:vc animated:YES];
            }];

        };
        
        popView.backBlock = ^{
            [view removeFromSuperview];
            [popView dismissViewControllerAnimated:NO completion:nil];
        };

    });

}

- (IBAction)backClick:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)createClick:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (IBAction)shareClick:(UIButton *)sender {
    UIImage *imageToShare = self.shareImage;
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[imageToShare] applicationActivities:nil];
    activityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook,
                                             UIActivityTypePostToTwitter,
                                             UIActivityTypePostToWeibo,
                                             UIActivityTypeMessage,
                                             UIActivityTypeMail,
                                             UIActivityTypeCopyToPasteboard,
                                             UIActivityTypeAssignToContact,
                                             UIActivityTypePostToTencentWeibo,
                                             UIActivityTypeAirDrop];
    [self presentViewController:activityVC animated:YES completion:nil];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
